package cn.xuchunh.campusbbs.ui.fragments;

import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;

import java.util.List;

import cn.xuchunh.campusbbs.R;
import cn.xuchunh.campusbbs.base.BaseFragment;
import cn.xuchunh.campusbbs.bean.SimpleData;
import cn.xuchunh.campusbbs.bean.User;
import cn.xuchunh.campusbbs.utils.IntentParamsKey;
import cn.xuchunh.campusbbs.widget.SimpleItemView;

/**
 * Created by XuChunH on 2015/10/22.
 */
public class UserProfileFragment extends BaseFragment {

    private User user;

    public static UserProfileFragment newInstance(User user) {

        Bundle args = new Bundle();
        args.putSerializable(IntentParamsKey.USER, user);
        UserProfileFragment fragment = new UserProfileFragment();
        fragment.setArguments(args);
        return fragment;
    }

    public UserProfileFragment() {
    }

    @Override
    protected void initView(View view) {
        LinearLayout root = ((LinearLayout) view.findViewById(R.id.content_root_view));

        List<SimpleData> profileList = user.getProfileList();
        for (SimpleData simpleData : profileList) {
            SimpleItemView simpleItemView = new SimpleItemView(getActivity());
            simpleItemView.setLabel(simpleData.getTitle());
            simpleItemView.setContent(simpleData.getData());
            root.addView(simpleItemView);
        }
    }

    @Override
    protected void beforeInitView() {
        setContentViewRes(R.layout.fragment_user_profile);
    }

    @Override
    protected void handleArgs(Bundle args) {
        if (args != null){
            user = (User) args.getSerializable(IntentParamsKey.USER);
            if(user == null){
                user = getUser();
            }
        }
    }
}
